package cn.userManager.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cn.userManager.mapper.UserMapperCustom;
import cn.userManager.po.User;
import cn.userManager.service.UserService;

@Controller
@RequestMapping("/check")
public class UserValidation {
	@Autowired
	private UserService userService;
	@RequestMapping(value = "/Code")
	public void checkCode(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		String verifyCode = req.getParameter("verifyCode");

		// * 2. 获取图片上真实的校验码

		String vcode = (String) req.getSession().getAttribute("vCode");

		// * 3. 进行忽略大小写比较，得到结果

		boolean b = verifyCode.equalsIgnoreCase(vcode);

		// * 4. 发送给客户端

		resp.getWriter().print(b);
	}

	@RequestMapping("/Name")
	public void checkName(HttpServletRequest req, HttpServletResponse resp) throws Exception {
		String username=req.getParameter("username");
		User user=userService.selectByName(username);
		boolean b=true;
		if(user!=null)
		{
			b=false;
		}
		resp.getWriter().print(b);
	}

	@RequestMapping("/Phone")
	public void checkPhone(HttpServletRequest req, HttpServletResponse resp) throws Exception {
		String phone_number = req.getParameter("phone_number");
		boolean b=true;
		User user=userService.selectByPhone(phone_number);
		if(user!=null)
		{
			b=false;
		}
		resp.getWriter().print(b);
	}
}
